/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openFuyao is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package config

import "time"

// OperationMode 操作模式
type OperationMode string

const (
	ModeQuery        OperationMode = "fileQuery"    // 文件查询
	ModeClean        OperationMode = "fileClean"    // 文件清理
	ModeProgramCheck OperationMode = "programCheck" // 程序检查

	DirectoryMode = 0755 // 目录权限：所有者可读、写、执行，组和其他用户可读和执行
	FileMode      = 0644 // 普通文件权限：所有者可读、写，组和其他用户只读
)

// AppConfig 应用配置
type AppConfig struct {
	Mode         OperationMode `json:"mode" yaml:"mode"`                   // 操作模式: query, clean
	LogFile      string        `json:"log_file" yaml:"log_file"`           // 日志文件路径
	OutputFormat string        `json:"output_format" yaml:"output_format"` // 输出格式
	Paths        []string      `json:"paths" yaml:"paths"`                 // 要操作的路径列表
	PathsDeal    bool          `json:"paths_deal" yaml:"paths_deal"`       // 路径是否需要处理

	// 清理相关配置
	CleanAuto    bool `json:"clean_auto" yaml:"clean_auto"`       // 是否自动清理（不询问）
	CleanConfirm bool `json:"clean_confirm" yaml:"clean_confirm"` // 清理前确认
	CleanDryRun  bool `json:"clean_dry_run" yaml:"clean_dry_run"` // 模拟运行，不实际删除

	ProgramList []string `json:"program_list" yaml:"program_list"` // 要检查的程序列表
}

// FileInfo 文件/文件夹信息
type FileInfo struct {
	Path        string `json:"path"`
	Exists      bool   `json:"exists"`
	IsDir       bool   `json:"is_dir"`
	Owner       string `json:"owner,omitempty"` // 文件所属用户
	Group       string `json:"group,omitempty"` // 文件所属用户组
	Permissions string `json:"permissions"`     // 文件权限
	Error       string `json:"error,omitempty"`
}

// QueryResult 查询结果
type QueryResult struct {
	Timestamp time.Time    `json:"timestamp"`
	Files     []FileInfo   `json:"files"`
	Summary   QuerySummary `json:"summary"`
}

// QuerySummary 查询汇总信息
type QuerySummary struct {
	TotalChecked int `json:"total_checked"`
	TotalExists  int `json:"total_exists"`
	TotalMissing int `json:"total_missing"`
	TotalDirs    int `json:"total_dirs"`
	TotalFiles   int `json:"total_files"`
}

// CleanResult 清理结果
type CleanResult struct {
	Timestamp time.Time    `json:"timestamp"`
	Deleted   []FileInfo   `json:"deleted"`
	Failed    []FileInfo   `json:"failed"`
	Skipped   []FileInfo   `json:"skipped"`
	Summary   CleanSummary `json:"summary"`
}

// CleanSummary 清理汇总信息
type CleanSummary struct {
	TotalChecked int `json:"total_checked"`
	TotalDeleted int `json:"total_deleted"`
	TotalFailed  int `json:"total_failed"`
	TotalSkipped int `json:"total_skipped"`
}

// ProgramInfo 程序信息
type ProgramInfo struct {
	Name      string `json:"name"`
	Installed bool   `json:"installed"`
	Version   string `json:"version,omitempty"`
	Path      string `json:"path,omitempty"`
	Error     string `json:"error,omitempty"`
}

// ProgramCheckResult 程序检查结果
type ProgramCheckResult struct {
	Timestamp time.Time           `json:"timestamp"`
	Programs  []ProgramInfo       `json:"programs"`
	Summary   ProgramCheckSummary `json:"summary"`
}

// ProgramCheckSummary 程序检查汇总
type ProgramCheckSummary struct {
	TotalChecked   int `json:"total_checked"`
	TotalInstalled int `json:"total_installed"`
	TotalMissing   int `json:"total_missing"`
}
